package com.qianli.cashmama.trade.application.channel;

import com.fqgj.common.api.Response;
import com.fqgj.common.utils.CollectionUtils;
import com.qianli.cashmama.trade.client.channel.ChannelQueryService;
import com.qianli.cashmama.trade.client.channel.response.ChannelInfoResponse;
import com.qianli.cashmama.trade.dao.TChannelCodeMappingDao;
import com.qianli.cashmama.trade.entity.TChannelCodeMappingEntity;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * ·
 *
 * @author liuming
 * Created on 下午8:17 2019/3/27.
 */
@Service("channelQueryService")
public class ChannelQueryServiceImpl implements ChannelQueryService {

    @Autowired
    TChannelCodeMappingDao tChannelCodeMappingDao;

    @Override
    public Response<List<ChannelInfoResponse>> queryChannelInfo() {
        List<ChannelInfoResponse> responseList = new ArrayList<>();
        List<TChannelCodeMappingEntity> list = tChannelCodeMappingDao.selectAllChannel();
        if (CollectionUtils.isNotEmpty(list)) {
            list.forEach(tChannelCodeMappingEntity -> {
                ChannelInfoResponse channelInfoResponse = new ChannelInfoResponse();
                BeanUtils.copyProperties(tChannelCodeMappingEntity, channelInfoResponse);
                responseList.add(channelInfoResponse);
            });
        }

        return Response.ok(responseList);
    }
}
